<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="统计分析"></uni-navbar></view>

		<view class="table-box">
			<u-table class="table-inner" border-color="#F8F8F8">
				<u-tr>
					<u-th>阅读内容</u-th>
					<u-th>浏览时长</u-th>
				</u-tr>
				<view class="table-cell" v-for="(item, index) of readList" :key="index">
					<u-tr>
						<u-td>{{ item.articleTitle }}</u-td>
						<u-td>
							<text class="text" @click="navTo('/pagesB/word/detail?id=' + item.articleId)">{{ item.duration || 0 }}分钟</text>
						</u-td>
					</u-tr>
				</view>
			</u-table>
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			id: '',
			fileList: [],
			readList: [],
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				// this.userId = this.userInfo.sysUser.id;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (type == 'add' && this.loading == 'loading') {
				return false;
			}
			if (type == 'add' && this.loading == 'nomore') {
				return false;
			}

			this.loading = 'loading';
			if (type != 'add') {
				this.pageNum = 1;
			}
			let url = '/dushuxuexi/articleReader/readList';
			let data = {
				type: '3',
				secType: '',
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				readUser: this.id
			};

			this.$request(url, data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.readList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.readList = this.readList.concat(res.data.records);
				this.loaded = true;
				if (this.readList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.table-box {
	clear: both;

	.name {
		display: flex;
		flex-wrap: nowrap;
		justify-content: center;

		.text {
			color: #333;
			width: 260rpx;
			text-align: left;
		}
	}

	.text {
		color: #0196fa;
	}

	.break-all {
		word-break: break-all;
	}

	.image {
		margin-right: 20rpx;
		width: 80rpx;
		height: 80rpx;
	}
}
</style>
